import plugin from '../../../lib/plugins/plugin.js'
import axios from 'axios';

export class mcv extends plugin {
    constructor() {
        super({
            name: '[xingchen-plugin] mcv',
            dsc: '[xingchen-plugin] mcv',
            event: 'message',
            priority: 1,
            rule: [
                {
                    reg: '^#?(mcv|MCV)$',
                    fnc: 'mcv'
                },
                {
                    reg: '^#?(mcbv|MCBV)$',
                    fnc: 'mcbv'
                }
            ]
        })
    }

    async mcv(e) {
        let data = await fetch('https://piston-meta.mojang.com/mc/game/version_manifest.json')
        if (data.status == 200) {
            let json = await data.json()
            let release = json.latest.release
            let snapshot = json.latest.snapshot
            let releasetime = json.versions.find(v => v.id == release).releaseTime
            let release_time = new Date(releasetime).toLocaleString()
            let snapshottime = json.versions.find(v => v.id == snapshot).releaseTime
            let snapshot_time = new Date(snapshottime).toLocaleString()
            let text = `目前启动器内最新版本为：\n最新版：${release}\n发布于：${release_time} (UTC+8)\n最新快照：${snapshot}\n发布于：${snapshot_time} (UTC+8)`
            await e.reply(text, true)
            return true
        }
        else {
            await e.reply('获取版本信息失败', true)
            return true
        }
    }
}